package com.jly.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;

/**
 * @author Liwenhao
 * @date 2022/3/24 10:29
 * @description
 */
@Configuration
public class ApplicationContextBean {

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();
//        //设置JSON数据转换器
//        restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
//        //使用OkHttp3Client作为http请求工具
//        OkHttp3ClientHttpRequestFactory requestFactory = new OkHttp3ClientHttpRequestFactory();
//        //设置连接超时时间,单位毫秒
//        requestFactory.setConnectTimeout(500000);
//        //设置读取超时时间，单位毫秒
//        requestFactory.setReadTimeout(500000);
//        restTemplate.setRequestFactory(requestFactory);
        return restTemplate;
    }
}
